﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 18/01/2009
// Time: 19:25
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of Warehouse.
	/// </summary>
	public class Warehouse : csharp.common.DefaultClass, csharp.common.IClass
	{
		#region private declaration
		private string _name;
		private string _register_date;
		private string _default;
		private string _company_id;
		#endregion
		
		public Warehouse()
		{
			clear();
			gsql.table = "common.warehouse";
			_sequence  = "common.warehouse_warehouse_id_seq";
		}
		
		#region properties
		public string name 
		{
			get { return _name; }
			set { _name = value; }
		}
		
		public string negisterDate 
		{
			get { return _register_date; }
			set { _register_date = value; }
		}
		
		public bool isDefault 
		{
			get { return Convert.ToBoolean(_default); }
			set { _default = Convert.ToString(value); }
		}
		
		public string companyId 
		{
			get { return _company_id; }
			set { _company_id = value; }
		}
		#endregion
	
		public void clear()
		{
			_id				= String.Empty;
			_name 			= String.Empty;
			_register_date = String.Empty;
			_default			= Boolean.FalseString;
			_company_id		= String.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id				= dr["warehouse_id"].ToString();
			_name				= dr["warehouse_name"].ToString();
			_register_date = dr["warehouse_register_date"].ToString();
			_default			= dr["warehouse_default"].ToString();
			_company_id		= dr["warehouse_company_id"].ToString();
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id, 				"warehouse_id");
			gsql.setValue(_name, 			"warehouse_name");
			gsql.setValue(_register_date, "warehouse_register_date");
			gsql.setValue(_default,			"warehouse_default");
			gsql.setValue(_company_id, 	"warehouse_company_id");
		}
		
	}
	
	public class Warehouses : csharp.common.DefaultList, csharp.common.IList
	{
		public Warehouses()
		{
			gsql.table = "common.warehouse";
		}
		
		public Warehouse get()
		{
			return (Warehouse)items[index];
		}
		
		public Warehouse get(int index)
		{
			return (Warehouse)items[index];
		}
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "warehouse_company_id = "+Information.companyId;
			gsql.additionalWhere = "ORDER BY warehouse_name";
			
			return mountList();
		}
		
		private bool mountList()
		{
			if (!gsql.execute())
			{
				msgErro= gsql.getMsgErro();
				return false;
			}
			
			items.Clear();
			int tam = gsql.getRowCount();
			for(int i=0; i < tam; i++)
			{
				Warehouse h = new Warehouse();
				h.get(gsql.getRow(i));
				
				items.Add(h);
			}
			return true;
		}		
	}
}
